<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商铺名称" prop="shopName">
        <el-input
            v-model="queryParams.shopName"
            placeholder="请输入商铺名称"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人" prop="legalPersonName">
        <el-input
            v-model="queryParams.legalPersonName"
            placeholder="请输入法人"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="价格区间">
        <el-row>
          <el-col :span="11">
            <el-input-number v-model="queryParams.minimumPrice" :controls="false" :precision="2" placeholder="最小价格"></el-input-number>
          </el-col>
          <el-col :span="2">-</el-col>
          <el-col :span="11">
            <el-input-number v-model="queryParams.maximumPrice" :controls="false"  :precision="2" placeholder="最大价格"></el-input-number>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择类型" clearable>
          <el-option
              v-for="dict in shop_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="Plus"
            @click="handleAdd"
            v-hasPermi="['ty:tyShop:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="Edit"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['ty:tyShop:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="Delete"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['ty:tyShop:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['ty:tyShop:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tyShopList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="商铺名称" width="300" align="center" prop="shopName"/>
      <el-table-column label="营业时间" align="center" prop="businessHours"/>
      <el-table-column label="现价" width="80" align="center" prop="nowPrice"/>
      <el-table-column label="详细地址" align="center" width="300" prop="address"/>
      <el-table-column label="类型" width="100" align="center" prop="type">
        <template #default="scope">
          <dict-tag :options="shop_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="评分" width="100" align="center" prop="rating"/>
      <el-table-column label="地区" width="100" align="center" prop="cityName"/>
      <el-table-column label="客服电话" width="150" align="center" prop="phone"/>
      <el-table-column label="操作" align="center" width="300" class-name="small-padding fixed-width" fixed="right">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['ty:tyShop:edit']">
            修改
          </el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['ty:tyShop:remove']">删除
          </el-button>
          <el-button link type="primary" icon="Money" @click="handlePackage(scope.row)">团购套餐</el-button>
<!--          <el-button link type="primary" icon="Money" @click="handleEvaluation(scope.row)">评价列表</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改商家入驻对话框 -->
    <el-dialog :title="title" v-model="open" width="1000px" append-to-body>
      <el-form ref="tyShopRef" :model="form" :rules="rules" label-width="80px">
        <span>基本信息</span>
        <el-divider border-style="double"/>
        <el-row>
          <el-col :span="12">
            <el-form-item label="商铺名称" prop="shopName">
              <el-input v-model="form.shopName" placeholder="请输入商铺名称" maxlength="20"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="营业时间" prop="businessHours">
              <el-input v-model="form.businessHours" placeholder="请输入营业时间" maxlength="20"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="类型" prop="type">
              <el-select v-model="form.type" placeholder="请选择类型" style="width: 100%">
                <el-option
                    v-for="dict in shop_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="原价" prop="originalPrice">
              <el-input-number :controls="false" min="0" :precision="2" v-model="form.originalPrice" placeholder="请输入原价"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="现价" prop="nowPrice">
              <el-input-number :controls="false" min="0" :precision="2" v-model="form.nowPrice" placeholder="请输入现价"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="价格单位" prop="priceUnit">
              <el-input v-model="form.priceUnit" placeholder="请输入价格单位" maxlength="10"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-col :span="24">
          <el-form-item label="详细地址" prop="address">
            <el-input v-model="form.address" type="textarea" placeholder="请输入内容"/>
          </el-form-item>
        </el-col>
        <el-row>
          <el-col :span="24">
            <map-component :key="mapComponentKey"
                :longitude="form.longitude" :latitude="form.latitude" @coordinateClicked="handleCoordinateClicked"
            ></map-component>
          </el-col>
        </el-row>
        <el-col :span="24">
          <el-form-item label="描述" prop="description">
            <el-input v-model="form.description" type="textarea" rows="6" placeholder="请输入内容"/>
          </el-form-item>
        </el-col>
        <el-row>
          <el-col :span="12">
            <el-form-item label="封面图" prop="mainImage">
              <image-upload v-model="form.mainImage" :limit="1"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-col :span="24">
          <el-form-item label="详情图片" prop="detailImage">
            <image-upload v-model="form.detailImage" :limit="8"/>
          </el-form-item>
        </el-col>
        <el-row>
          <el-col :span="12">
            <el-form-item label="客服电话" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入客服电话"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合伙人" prop="partnersId" v-if="useUserStore().userType === '0'">
              <partners-select v-model="form.partnersId"></partners-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="省市" prop="cityCode">
              <el-cascader-city v-model="form.cityCode" :is-save="useUserStore().userType === '0' ?true:false"></el-cascader-city>
            </el-form-item>
          </el-col>
        </el-row>

        <span>审核信息</span>
        <el-divider border-style="double"/>

        <el-row>
          <el-col :span="12">
            <el-form-item label="营业执照" prop="businessLicenseNumber">
              <el-input v-model="form.businessLicenseNumber" placeholder="请输入营业执照号码"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人" prop="legalPersonName">
              <el-input v-model="form.legalPersonName" placeholder="请输入法定代表人" maxlength="10"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="身份证号" prop="idCardNumber">
              <el-input v-model="form.idCardNumber" placeholder="请输入身份证号码"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="身份证正" prop="idCardFrontImage">
              <image-upload v-model="form.idCardFrontImage" :limit="1"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="身份证反" prop="idCardBackImage">
              <image-upload v-model="form.idCardBackImage" :limit="1"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="营业执照" prop="businessLicenseImage">
              <image-upload v-model="form.businessLicenseImage" :limit="1"/>
            </el-form-item>
          </el-col>
        </el-row>
<!--        <el-row>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="店铺状态" prop="shopStatus">-->
<!--              <el-select v-model="form.shopStatus" placeholder="请选择店铺状态" style="width: 100%">-->
<!--                <el-option-->
<!--                    v-for="dict in shop_status"-->
<!--                    :key="dict.value"-->
<!--                    :label="dict.label"-->
<!--                    :value="dict.value"-->
<!--                ></el-option>-->
<!--              </el-select>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="审核状态" prop="shopExamineStatus">-->
<!--              <el-select v-model="form.shopExamineStatus"-->
<!--                         placeholder="请选择店铺审核状态" style="width: 100%">-->
<!--                <el-option-->
<!--                    v-for="dict in shop_examine_status"-->
<!--                    :key="dict.value"-->
<!--                    :label="dict.label"-->
<!--                    :value="dict.value"-->
<!--                ></el-option>-->
<!--              </el-select>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->
        <el-row>
          <el-col :span="12">
            <el-form-item label="签约起止" prop="openTime">
              <el-date-picker
                  clearable
                  v-model="openTimeRange"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="YYYY-MM-DD"
                  @change="handleOpenTimeChange"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="签约年限" prop="contractYears">
              <el-input v-model="form.contractYears" placeholder="请输入签约年限" :readonly="true"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="签约时间" prop="contractTime">
              <el-date-picker clearable
                              v-model="form.contractTime"
                              type="date"
                              value-format="YYYY-MM-DD"
                              placeholder="选择签约时间" style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="归属" prop="attribution">
              <el-select v-model="form.attribution" placeholder="请选择归属" style="width: 100%">
                <el-option
                    v-for="dict in partners_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系人" prop="contactPerson">
              <el-input v-model="form.contactPerson" placeholder="请输入联系人姓名" maxlength="5"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系邮箱" prop="contactEmail">
              <el-input v-model="form.contactEmail" placeholder="请输入联系邮箱" maxlength="30"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系地址" prop="contactAddress">
              <el-input v-model="form.contactAddress" placeholder="请输入联系地址" maxlength="30"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="银行名称" prop="bankName">
              <el-input v-model="form.bankName" placeholder="请输入银行名称" maxlength="20"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="开户行" prop="openBankName">
              <el-input v-model="form.openBankName" placeholder="请输入开户行名称" maxlength="30"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="银行卡号" prop="bankcardNumber">
              <el-input v-model="form.bankcardNumber" placeholder="请输入银行卡号" maxlength="20"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="手机号" prop="bankcardPhone">
              <el-input v-model="form.bankcardPhone" placeholder="请输入银行卡绑定手机号" maxlength="11"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="业务员" prop="saleUserId">
              <user-select v-model="form.saleUserId" :userType="3"></user-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="核销手机" prop="userPhone">
              <el-input v-model="form.userPhone" placeholder="请输入核销手机号"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="TyShop">
import {listTyShop, getTyShop, delTyShop, addTyShop, updateTyShop,checkUserPhone} from "@/api/ty/tyShop";
import PartnersSelect from "@/components/PartnersSelect/index.vue";
import UserSelect from "@/components/UserSelect/index"
import router from "@/router";
import {watch,onBeforeUnmount,ref} from "vue";
import useUserStore from "@/store/modules/user";

const {proxy} = getCurrentInstance();
const {
  shop_status,
  shop_examine_status,
  shop_type,
  partners_type
} = proxy.useDict('shop_status', 'shop_examine_status', 'shop_type', 'partners_type');

const tyShopList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const mapComponentKey = ref(0)
const title = ref("");
const openTimeRange = ref([]);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    shopName: null,
    type: null,
    phone: null,
  },
  rules: {
    userPhone: [
      // {required: true, message: "核销手机号不能为空！", trigger: "blur"},
      // {pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: "请输入正确的手机号码", trigger: "blur"},
      // {
      //   validator: (rule, value, callback) => {
      //     if (value.length >= 11) {
      //       // 调用接口获取返回数据
      //       checkUserPhone({phone:value}).then(data => {
      //         if (data.code === 200) {
      //           callback();
      //         } else {
      //           callback(new Error(data.msg));
      //         }
      //       });
      //     }
      //   },
      //   message: "该手机号尚未注册透氧用户",
      // }
    ],
    shopName:[
      {required: true, message: "商铺名称不能为空！", trigger: "change"},
    ],
    businessHours:[
      {required: true, message: "营业时间不能为空！", trigger: "change"},
    ],
    // type:[
    //   {required: true, message: "类型不能为空！", trigger: "change"},
    // ],
    // originalPrice:[
    //   {required: true, message: "原价（元）不能为空！", trigger: "change"},
    // ],
    nowPrice:[
      {required: true, message: "现价（元）不能为空！", trigger: "change"},
      // {
      //   validator: validateNowPrice,
      //   message: "现价不能大于原价",
      //   trigger: 'blur'
      // }
    ],
    priceUnit:[
      {required: true, message: "价格单位不能为空！", trigger: "change"},
    ],
    address:[
      {required: true, message: "详细地址不能为空！", trigger: "change"},
    ],
    description:[
      {required: true, message: "描述不能为空！", trigger: "change"},
    ],
    mainImage:[
      {required: true, message: "封面图不能为空！", trigger: "change"},
    ],
    openTime:[
      {required: true, message: "请选择签约起止时间！", trigger: "change"},
    ],
    detailImage:[
      {required: true, message: "详细图片不能为空！", trigger: "change"},
    ],
    phone:[
      {required: true, message: "客服电话不能为空！", trigger: "change"},
      {pattern: /^(1[3|4|5|6|7|8|9]\d{9})$|^(\d{3,4}-\d{7,8})$/, message: "请输入正确的客服电话", trigger: "blur"}
    ],
    businessLicenseNumber:[
      // {required: true, message: "营业执照不能为空！", trigger: "change"},
      {
        pattern: /^[A-Za-z0-9]{18}$/,
        message: '请输入由字母或数字组成的18位字符',
        trigger: 'change'
      }
    ],
    legalPersonName:[
      {required: true, message: "法人不能为空！", trigger: "change"},
    ],
    idCardNumber:[
      // {required: true, message: "身份证号不能为空！", trigger: "change"},
      {
        pattern:  /^[0-9a-zA-Z]{18}$/,
        message: '请输入正确的身份证号码',
        trigger: 'change'
      }
    ],
    // idCardFrontImage:[
    //   {required: true, message: "身份证正不能为空！", trigger: "change"},
    // ],
    // idCardBackImage:[
    //   {required: true, message: "身份证反不能为空！", trigger: "change"},
    // ],
    businessLicenseImage:[
      {required: true, message: "请上传营业执照！", trigger: "change"},
    ],
    contractTime:[
      {required: true, message: "请选择签约时间！", trigger: "change"},
    ],
    contractYears:[
      {required: true, message: "签约年限不能为空！", trigger: "change"},
    ],
    attribution:[
      {required: true, message: "请选择归属！", trigger: "change"},
    ],
    bankName:[
      {required: true, message: "银行名称不能为空！", trigger: "change"},
    ],
    openBankName:[
      {required: true, message: "开户行不能为空！", trigger: "change"},
    ],
    bankcardNumber:[
      {required: true, message: "银行卡号不能为空！", trigger: "change"},
    ],
    bankcardPhone:[
      {required: true, message: "手机号不能为空！", trigger: "change"},
      {
        pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
        message: "请输入正确的手机号码",
        trigger: "blur"
      }
    ],
  }
});

const {queryParams, form, rules} = toRefs(data);

/** 查询商家入驻列表 */
function getList() {
  loading.value = true;
  listTyShop(queryParams.value).then(response => {
    tyShopList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: undefined,
    shopName: undefined,
    businessHours: undefined,
    originalPrice: undefined,
    nowPrice: undefined,
    priceUnit: undefined,
    latitude: 31.8639,
    longitude: 118.8083,
    address: undefined,
    description: undefined,
    mainImage: undefined,
    detailImage: undefined,
    type: undefined,
    userId: undefined,
    phone: undefined,
    tag: undefined,
    partnersId: undefined,
    cityCode: undefined,
    cityName: undefined,
    createTime: undefined,
    updateTime: undefined,
    forward: undefined,
    view: undefined,
    businessLicenseNumber: undefined,
    legalPersonName: undefined,
    idCardNumber: undefined,
    idCardFrontImage: undefined,
    idCardBackImage: undefined,
    businessLicenseImage: undefined,
    shopStatus: undefined,
    shopExamineStatus: undefined,
    openTime: undefined,
    closeTime: undefined,
    contactPerson: undefined,
    contactEmail: undefined,
    contactAddress: undefined,
    bankName: undefined,
    openBankName: undefined,
    bankcardNumber: undefined,
    bankcardPhone: undefined,
    contractTime: undefined,
    contractYears: undefined,
    contactInfo: undefined,
    commissionRate: undefined,
    attribution: undefined,
    userPhone:undefined,
    saleUserId: undefined
  };
  openTimeRange.value = [];
  mapComponentKey.value += 1;
  proxy.resetForm("tyShopRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  queryParams.value.minimumPrice = null;
  queryParams.value.maximumPrice = null;
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加商家入驻";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getTyShop(_id).then(response => {
    form.value = response.data;
    form.value.partnersId = (response.data.partnersId === null)?null:response.data.partnersId.toString();
    openTimeRange.value = [response.data.openTime, response.data.closeTime];
    open.value = true;
    title.value = "修改商家入驻";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["tyShopRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateTyShop(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addTyShop(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除该数据项？').then(function() {
    return delTyShop(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {
  });
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('system/tyShop/export', {
    ...queryParams.value
  }, `tyShop_${new Date().getTime()}.xlsx`)
}

function handlePackage(row) {
  const id = row.id || ids.value[0];
  const packageableType = "Business";
  router.push({path: "/shop/package/index/" + id, query: {pageNum: queryParams.value.pageNum,packageableType:packageableType}});
}

function handleEvaluation(row) {
  const id = row.id || ids.value[0];
  const packageableType = "Business";
  router.push({path: "/shop/tyEvaluation/index/" + id, query: {pageNum: queryParams.value.pageNum,packageableType:packageableType}});
}

function handleCoordinateClicked(coordinate) {
  console.log(coordinate)
  // 更新经纬度
  form.value.longitude = coordinate.lng;
  form.value.latitude = coordinate.lat;
  form.value.address = coordinate.address;
}
function validateNowPrice(rule, value, callback) {
  if (value >= form.value.originalPrice) {
    callback(new Error('现价需要小于原价'));
  } else {
    callback();
  }
}
function handleOpenTimeChange(value) {
  if (value && value.length === 2) {
    form.value.openTime = value[0];
    form.value.closeTime = value[1];

    const startDate = new Date(value[0]);
    const endDate = new Date(value[1]);

    const MS_PER_MONTH = 1000 * 60 * 60 * 24 * 30;

    const timeDifference = endDate - startDate;
    const monthsDifference = timeDifference / MS_PER_MONTH;

    // if (monthsDifference >= 12) {
    //   const years = Math.floor(monthsDifference / 12);
    //   const remainingMonths = Math.floor(monthsDifference % 12);
    //
    //   if (remainingMonths > 0) {
    //     form.value.contractYears = `${years}年${remainingMonths}个月`;
    //   } else {
    //     form.value.contractYears = `${years}年`;
    //   }
    // } else {
      form.value.contractYears = `${Math.floor(monthsDifference)}个月`;
    // }
  }
}




getList();
const stopWatching = watch(() => useUserStore().cascaderKey, (v) => {
  getList();
}, { immediate: true });
onBeforeUnmount(() => {
  stopWatching();
});
</script>
